﻿@* @page "/trace"
@page "/trace/{TraceId}" //for scheduler  *@
@inject I18n I18n
@inject NavigationManager navigation

<PageTitle>@I18n.Trace("Trace")</PageTitle>

<TscTrace PageMode StartDateTime="ToDateTime(StartTime)" EndDateTime="ToDateTime(EndTime)" Keyword="@(string.IsNullOrEmpty(TraceId)?Keyword:TraceId)" Type="@Type" Service="@Service" />

@code {

    [Parameter]
    public string TraceId { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string Keyword { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string StartTime { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string Service { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string EndTime { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public string Type { get; set; }

    DateTime ToDateTime(string str)
    {
        if (DateTime.TryParse(str, out var time))
            return time;
        return DateTime.MinValue;
    }

    protected override void OnAfterRender(bool firstRender)
    {
        if (!firstRender)
        {
            navigation.NavigateTo("/trace", true);
            return;
        }
        base.OnAfterRender(firstRender);
    }
}